﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FlowerLibrary;

namespace Lab5_WinForms
{
    public partial class Form1 : Form
    {
        Creator[] creators = { new ConcretCreatorMarguerite(), new ConcretCreatorGladiolus(), new ConcretCreatorClove() };
        FlowerContainer bouquet = new FlowerContainer();
        public Form1()
        {
            InitializeComponent();
        }

        private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows[0].Index != dataGridView1.RowCount - 1)
                dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView2.RowCount = 3;
            dataGridView2.ColumnCount = 3;
            dataGridView1.RowCount = 1;
            dataGridView1.ColumnCount = 3;

            dataGridView2.Columns[0].HeaderText = "Name";
            dataGridView2.Columns[1].HeaderText = "Height";
            dataGridView2.Columns[2].HeaderText = "Price";

            dataGridView1.Columns[0].HeaderText = "Name";
            dataGridView1.Columns[1].HeaderText = "Height";
            dataGridView1.Columns[2].HeaderText = "Price";

            dataGridView2.Rows[0].Cells[0].Value = "Marguerite";
            dataGridView2.Rows[0].Cells[1].Value = FlowerContainer.MargueriteHeight.ToString();
            dataGridView2.Rows[0].Cells[2].Value = FlowerContainer.MargueritePrice.ToString();

            dataGridView2.Rows[1].Cells[0].Value = "Gladiolus";
            dataGridView2.Rows[1].Cells[1].Value = FlowerContainer.GladiolusHeight.ToString();
            dataGridView2.Rows[1].Cells[2].Value = FlowerContainer.GladiolusPrice.ToString();

            dataGridView2.Rows[2].Cells[0].Value = "Clove";
            dataGridView2.Rows[2].Cells[1].Value = FlowerContainer.CloveHeight.ToString();
            dataGridView2.Rows[2].Cells[2].Value = FlowerContainer.ClovePrice.ToString();
        }

        private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            AbstractFlower fl = null;
            string[] line;
            fl = creators[dataGridView2.SelectedRows[0].Index].FactoryMethod();
            line = fl.ToString().Split(' ');
            bouquet.AddNewFlower(fl);
            dataGridView1.Rows.Add(line);
            label1.Text = "Total price: " + bouquet.GetTotalPrice().ToString();
        }

        private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            bouquet.DeleteFlower(e.RowIndex);
            label1.Text = "Total price: " +  bouquet.GetTotalPrice().ToString();

        }

        private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                dataGridView1.CurrentCell = dataGridView1[e.ColumnIndex, e.RowIndex];
                dataGridView1.CurrentRow.Selected = true;
            }
        }
    }
}
